#include "routines.h"
/************************************************************************/
/* D = Pt
sigma tCt/(1+r)t
-----------
sigma Ct/(1+r)t   
Bond duration using discrete, annual compounding and a .at term structure                                                                  */
/************************************************************************/
double bonds_duration_discrete(const vector<double>& times,
							   const vector<double>& cashflows,
							   const double& r) {
	double B=0;
	double D=0;
	for (int i=0;i<times.size();i++){
		D += times[i] * cashflows[i] / pow(1+r,times[i]);
		B += cashflows[i] / pow(1+r,times[i]);
	};
	return D/B;
};